package server.workwithgarage;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import abstractservlet.AbstractServlet;
import autoservice.api.controller.IAutoservice;
import controllers.Autoservice;

@WebServlet("/GetNumberFreePlaces")
public class GetNumberFreePlaces extends AbstractServlet {
	private static final long serialVersionUID = 1L;
	private IAutoservice autoservice = Autoservice.getInstance();
	private static final String GET_NUMBER_FREE_PLACE_PAGE = "/workwithgaragepages/GetNumberFreePlacePage.jsp";
	private static final String GET_NUMBER_FREE_PLACE_PAGE_ON_DATE = "/workwithgaragepages/GetNumberFreePlacesOnDate.jsp";
	private static final String DATE = "date";
	private static final String GET_NUMBER_FREE_PLACES_OPERAT = "number free places";
	private static final String GET_NUMBER_FREE_PLACES_ON_DATE_OPERAT = "number free places on date";

	public GetNumberFreePlaces() {
		super();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String answer = autoservice.getEmptyGarage().get(0);
		super.navigate(request, response, GET_NUMBER_FREE_PLACES_OPERAT,
				answer, GET_NUMBER_FREE_PLACE_PAGE);

	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String date = request.getParameter(DATE);
		super.navigate(request, response,
				GET_NUMBER_FREE_PLACES_ON_DATE_OPERAT, autoservice
						.getFreePlacesOnDate(date).get(0),
				GET_NUMBER_FREE_PLACE_PAGE_ON_DATE);

	}

}
